package demo;/*
Listing 2.5 Retrieving Servlet Context Information
 */

import javax.servlet.*;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.io.IOException;

public class ContextDemoServlet implements Servlet {
    ServletConfig servletConfig;
    public void init(ServletConfig config) throws ServletException {
        servletConfig = config;
    }
    public void destroy() {
    }

    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
        ServletContext servletContext = servletConfig.getServletContext();
        Enumeration attributes = servletContext.getAttributeNames();
        PrintWriter out=response.getWriter();
        while (attributes.hasMoreElements()) {
            String attribute = (String) attributes.nextElement();
            out.println("Attribute name : " + attribute);
            out.println("Attribute value : " +
                    servletContext.getAttribute(attribute));
        }
        out.println("Major version : " + servletContext.getMajorVersion());
        out.println("Minor version : " + servletContext.getMinorVersion());
        out.println("Server info : " +  servletContext.getServerInfo());
    }
    public String getServletInfo() {
        return null;
    }
    public ServletConfig getServletConfig() {
        return null;
    }
}